Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: codesize reduction #231

Merged
merged 25 commits into from
Oct 16, 2024
Merged

refactor: codesize reduction #231

merged 25 commits into from
Oct 16, 2024

Conversation

Zer0dot
Copy link
Contributor

@Zer0dot Zer0dot commented Oct 7, 2024

Motivation

We need to reduce code size to fit under the Spurious Dragon limit of 24576 bytes.

Solution

Various refactors, including:

  • Merging certain similar functions and introducing branching.
  • Removing domainSeparator() and potentially other offchain-computable functions.
  • Move certain functions to external libraries if possible and the gas impact to do so is low.

Copy link

octane-security-app bot commented Oct 7, 2024

Summary by Octane

New Contracts

No new contracts were added in this PR.

Updated Contracts

  • ModularAccountBase.sol: The smart contract now supports both create and create2 deployments with an isCreate2 switch and integrates ExecutionInstallDelegate for execution handling.
  • ModularAccountView.sol: The smart contract replaces KnownSelectorsLib with NativeFunctionDelegate, adding an internal delegate for native function determination.

🔗 Commit Hash: d7d699a

@Zer0dot Zer0dot force-pushed the zer0dot/codesize-refactor branch from 69ff270 to 5340e72 Compare October 7, 2024 23:32
Copy link

github-actions bot commented Oct 7, 2024

Contract sizes:

| Contract                      | Size (B) | Margin (B) |
|-------------------------------|----------|------------|
| AccountFactory                |    4,814 |     19,762 |
| AllowlistModule               |    9,903 |     14,673 |
| ExecutionInstallDelegate      |    5,694 |     18,882 |
| ModularAccount                |   21,971 |      2,605 |
| NativeFunctionDelegate        |      434 |     24,142 |
| NativeTokenLimitModule        |    4,258 |     20,318 |
| PaymasterGuardModule          |    1,797 |     22,779 |
| SemiModularAccountBytecode    |   24,045 |        531 |
| SemiModularAccountStorageOnly |   24,539 |         37 |
| SingleSignerValidationModule  |    4,300 |     20,276 |
| TimeRangeModule               |    2,000 |     22,576 |
| WebAuthnValidationModule      |    7,854 |     16,722 |

Code coverage:

File % Lines % Statements % Branches % Funcs
src/account/AccountBase.sol 100.00% (8/8) 100.00% (7/7) 100.00% (2/2) 100.00% (4/4)
src/account/AccountStorageInitializable.sol 100.00% (19/19) 100.00% (26/26) 100.00% (5/5) 100.00% (2/2)
src/account/ModularAccount.sol 100.00% (2/2) 100.00% (2/2) 100.00% (0/0) 100.00% (3/3)
src/account/ModularAccountBase.sol 98.99% (294/297) 96.29% (363/377) 77.59% (45/58) 100.00% (36/36)
src/account/ModularAccountView.sol 100.00% (24/24) 100.00% (28/28) 100.00% (2/2) 100.00% (4/4)
src/account/ModuleManagerInternals.sol 95.08% (58/61) 96.20% (76/79) 62.50% (5/8) 100.00% (3/3)
src/account/SemiModularAccountBase.sol 87.93% (51/58) 91.67% (77/84) 66.67% (10/15) 100.00% (14/14)
src/account/SemiModularAccountBytecode.sol 100.00% (6/6) 100.00% (7/7) 100.00% (1/1) 66.67% (2/3)
src/account/SemiModularAccountStorageOnly.sol 80.00% (4/5) 83.33% (5/6) 100.00% (0/0) 66.67% (2/3)
src/account/TokenReceiver.sol 33.33% (1/3) 33.33% (1/3) 100.00% (0/0) 33.33% (1/3)
src/factory/AccountFactory.sol 70.59% (24/34) 76.09% (35/46) 40.00% (2/5) 58.33% (7/12)
src/helpers/ExecutionInstallDelegate.sol 92.59% (50/54) 92.96% (66/71) 40.00% (2/5) 100.00% (7/7)
src/helpers/NativeFunctionDelegate.sol 100.00% (16/16) 100.00% (30/30) 100.00% (0/0) 100.00% (1/1)
src/libraries/ERC7739ReplaySafeWrapperLib.sol 85.88% (73/85) 85.87% (79/92) 66.67% (2/3) 87.50% (7/8)
src/libraries/ExecutionLib.sol 98.92% (274/277) 98.15% (266/271) 84.85% (28/33) 100.00% (24/24)
src/libraries/KnownSelectorsLib.sol 100.00% (15/15) 100.00% (32/32) 100.00% (0/0) 100.00% (2/2)
src/libraries/LinkedListSetLib.sol 94.00% (47/50) 96.25% (77/80) 66.67% (4/6) 100.00% (8/8)
src/libraries/MemManagementLib.sol 100.00% (54/54) 100.00% (70/70) 100.00% (0/0) 100.00% (12/12)
src/libraries/ModuleInstallCommons.sol 57.14% (8/14) 42.11% (8/19) 75.00% (3/4) 100.00% (3/3)
src/modules/ModuleBase.sol 100.00% (13/13) 94.12% (16/17) 100.00% (2/2) 100.00% (3/3)
src/modules/permissions/AllowlistModule.sol 86.05% (74/86) 85.71% (96/112) 78.26% (18/23) 50.00% (9/18)
src/modules/permissions/NativeTokenLimitModule.sol 87.18% (34/39) 89.29% (50/56) 88.89% (8/9) 54.55% (6/11)
src/modules/permissions/PaymasterGuardModule.sol 90.00% (9/10) 86.67% (13/15) 100.00% (2/2) 71.43% (5/7)
src/modules/permissions/TimeRangeModule.sol 83.33% (10/12) 80.00% (16/20) 100.00% (1/1) 75.00% (6/8)
src/modules/validation/SingleSignerValidationModule.sol 92.00% (23/25) 81.08% (30/37) 62.50% (5/8) 90.00% (9/10)
src/modules/validation/WebAuthnValidationModule.sol 61.11% (11/18) 66.67% (18/27) 100.00% (3/3) 60.00% (6/10)
Total 93.54% (1202/1285) 92.57% (1494/1614) 76.92% (150/195) 84.93% (186/219)

Copy link

octane-security-app bot commented Oct 7, 2024

Overview

Vulnerabilities found: 6                                                                                
Severity breakdown: 2 Critical, 2 High, 2 Medium

Detailed findings

src/account/ModularAccountBase.sol


🔗 Commit Hash: d7d699a
🛡️ Octane Dashboard: All vulnerabilities

@Zer0dot Zer0dot force-pushed the zer0dot/codesize-refactor branch 2 times, most recently from c8f1ff5 to dea2d9c Compare October 11, 2024 19:31
@Zer0dot Zer0dot marked this pull request as ready for review October 11, 2024 19:35
@Zer0dot Zer0dot force-pushed the zer0dot/codesize-refactor branch from 6a8cfa7 to 250cd57 Compare October 11, 2024 22:10
@Zer0dot Zer0dot marked this pull request as draft October 14, 2024 16:33
@Zer0dot Zer0dot force-pushed the zer0dot/codesize-refactor branch from 78467a7 to 35e0d20 Compare October 16, 2024 00:11
@Zer0dot Zer0dot marked this pull request as ready for review October 16, 2024 00:26
src/account/ModularAccountBase.sol Outdated Show resolved Hide resolved
src/account/ModularAccountBase.sol Outdated Show resolved Hide resolved
@Zer0dot Zer0dot force-pushed the zer0dot/codesize-refactor branch 4 times, most recently from 6106d8d to 631f31f Compare October 16, 2024 22:37
@Zer0dot Zer0dot force-pushed the zer0dot/codesize-refactor branch from af54caf to 8b3da4f Compare October 16, 2024 23:04
src/account/ModularAccountBase.sol Outdated Show resolved Hide resolved
src/libraries/ExecutionLib.sol Outdated Show resolved Hide resolved
@Zer0dot Zer0dot merged commit de20d70 into develop Oct 16, 2024
6 checks passed
@Zer0dot Zer0dot deleted the zer0dot/codesize-refactor branch October 16, 2024 23:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants